#define OPEN   1
#define CLOSED -1

#define BUF_SIZE 100

#define COM1_INT_ID     0x000C
#define COM1_BASE       0x3F8
#define COM1_INT_EN     0x3F9
#define COM1_BRD_LSB    0x3F8
#define COM1_BRD_MSB    0x3F9
#define COM1_INT_ID_REG 0x3FA
#define COM1_LC         0x3FB
#define COM1_MC         0x3FC
#define COM1_LS         0x3FD
#define COM1_MS         0x3FE
#define PIC_MASK        0x21
#define PIC_CMD         0x20
#define EOI             0x20

//com_read errors
#define NOT_OPEN          -301
#define INVALID_ADD       -302
#define INVALID_COUNT_ADD -303
#define BUSY              -304

//com_open errors
#define INVALID_FLAG -101
#define INVALID_BAUD -102
#define PORT_OPEN    -103

#define PORT_CLOSED  -201

//com_write errors
#define PORT_NOT_OPEN   -401
#define INVALID_BUF_ADD -402
#define INVALID_COUNT   -403
#define DEVICE_BUSY     -404

#define IO 0
#define IOCOMP 1


int ioflag = IO;

void exit();
void comhand();
int com_close();
int com_read(char* buf_p, int *count_p);
int com_open(int *eflag_p, int baud_rate);
int com_write(char* buf_p, int *count_p);
void interrupt inter(...);
void read_port();
void setDCB(int *eflag_p);
void write_port();

void push_char(char c);
char pull_char(void);
void interrupt (*oldfunc) (...);
struct DCB {
	//Open or Closed
	int ocFlag;
	//Event Flag
	int *eFlag;
	//Status Code
	int sCode;
	
	//Addresses and Counters associated with input buffer
	char* in_buff;
	int *in_count;
	int in_done;
	
	//Addresses and counters associated with output buffer
	char* out_buff;
	int *out_count;
	int out_done;
	
	char ring_buffer[BUF_SIZE];
	int ring_buffer_in;
	int ring_buffer_out;
	//Count of the number of characters in buffer
	int ring_buffer_count;
};
typedef struct DCB Dev_Con_Block;
typedef Dev_Con_Block* DCB_Pointer;